<?php $this->load->view('common/header');?>
<body>
<!-- login [[-->
<div class="login">
    <div class="logo">
        <img src="<?php echo $viewmulu;?>images/logo.png">
        <p>加入我们 用销售成就事业</p>
    </div>
    <div class="label">
    	<ul>
        	<li>
            	<span class="input">
                	<i class="ico ico_a"></i>
                	<input placeholder="请输入您的手机号码" id="mobile">
                </span>
            </li>
        	<li>
                <a href="javascript:;" class="code able" id="getCode">获取验证码</a>
            	<span class="input" placeholder="请输入验证码">
                	<i class="ico ico_b"></i>
                	<input placeholder="请输入验证码" id="code">
                </span>
            </li>
        </ul>
    </div>
</div>
<!--]] login -->
<!-- nav_box [[-->
<div class="nav_box">
	<a href="javascript:;" id="doLogin" >立即登录</a>
</div>
<script type="text/javascript">
    var baseurl='<?php echo base_url()?>';
    $(document).on("click",'#getCode.able',function(){
        var phone = $("#mobile").val();
        if(phone == "" || undefined){
            layer.msg("请填写手机号");
            return false;
        }
        var URL= baseurl+"index.php/home/ajax_send_sms";
        $.getJSON(URL,{'mobile':phone},function(logJson) {
            layer.msg(logJson.msg);
        });
        $("#getCode").html("发送中..").removeClass('able');
        setTimeout(time,1000)
    })
    function time(){
        var time = 60;
        var countDown = setInterval(fun,1000);
        function fun(){
            --time;
            $('#getCode').html(time+'s后获取');
            if (time == 0) {
                clearInterval(countDown);
                $('#getCode').html('重新获取').addClass('able');
            }
        }
    }
    // 提交
    $("#doLogin").on("click",function(){

        var mobile = $("#mobile").val();
        var yzm = $("#code").val();
        var csrf_str = $("#csrf_test_name").val();
        var myreg = /^((\d{3}-\d{8}|\d{4}-\d{7,8})|(1[3|5|7|8][0-9]{9}))$/;
        if (mobile=="") {
            layer.msg('请填写手机号码');
            return false;
        }
        if(!myreg.test(mobile)){
            layer.msg("手机号格式不正确");
            return false;
        }
        if (yzm=="") {
            layer.msg('请填写手机验证码');
            return false;
        }
        var URL= baseurl+"index.php/home/sms_login_in";
        $.ajax({
            type: "post",
            url: URL,
            dataType:'json',
            data: {
                'mobile':mobile,
                'yzm':yzm,
                'csrf_test_name': ci_csrf_token()
            },
            success: function(data){
                if(data.code == 200){
                    layer.msg('登录成功', {
                        time: 1000, //1s后自动关闭
                        shade: 0.1
                    },function () {
                        if(data.url){
                            window.location.href = data.url;
                        }else{
                            window.location.href = "<?php echo site_url('home/home');?>";
                        }
                    });
                }else{
                    $(".<?php echo $this->security->get_csrf_token_name();?>").val(data.code);
                    layer.msg(data.msg);
                    return false;
                }

            }
        });
    });
</script>
<!--]] nav_box -->
</body>
</html>
